package com.example.neteasecloudmusic.ui.player;

import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.widget.Toast;

import com.example.neteasecloudmusic.R;
import com.example.neteasecloudmusic.bean.SongDetailInfo;
import com.example.neteasecloudmusic.bean.playListBean.Tracks;


import java.io.IOException;
import java.util.List;

public class MusicRelateOptions {
    private MediaPlayer mediaPlayer;
    private static List<SongDetailInfo> songDetailInfos;
    private static String PATH;

    public MusicRelateOptions(MediaPlayer mediaPlayer, List<SongDetailInfo> songDetailInfos, String PATH) {
        this.mediaPlayer = mediaPlayer;
        this.songDetailInfos = songDetailInfos;
        this.PATH = PATH;
    }

    public void play(String musicUrl) throws IOException {
        mediaPlayer.reset();
        PATH = musicUrl;
        mediaPlayer.setDataSource(PATH);
        mediaPlayer.prepare();
        mediaPlayer.start();
    }


    public int NextMusic(Integer position){
        mediaPlayer.stop();
        try {
            mediaPlayer.reset();
            mediaPlayer.setDataSource(songDetailInfos.get(position % songDetailInfos.size()).getUrl());
            mediaPlayer.prepare();
            mediaPlayer.start();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return position;
    }
    public int PreMusic(Integer position) {
        return NextMusic(position);
    }

}
